home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Freeware / Programare / nvu / nvu-0.80-win32-installer-full.exe / {app} / chrome / cascades.jar / content / cascades / EdCssProps-utils.js < prev    next >
Text File  |  2005-01-31  |  6KB  |  167 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is CaScadeS, a stylesheet editor for Composer.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Daniel Glazman.
  18.  * Portions created by the Initial Developer are Copyright (C) 2002
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Original author: Daniel Glazman <daniel@glazman.org>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. // * retrieves the index of the selected entry in a tree
  39. //   param XULElement tree
  40. //   return integer
  41. function getSelectedItem(tree)
  42. {
  43.   if (tree.treeBoxObject.selection.count == 1)
  44.     return tree.contentView.getItemAtIndex(tree.currentIndex);
  45.   else
  46.     return null;
  47. }
  48.  
  49. // * retrieves the importance of the index-nth style declaration in a rule
  50. //   param DOMCSSRule styleRule
  51. //   param integer index
  52. //   return String
  53. function GetDeclarationImportance(styleRule, index)
  54. {
  55.   var pName = styleRule.style.item(index);
  56.   return styleRule.style.getPropertyPriority(pName);
  57. }
  58.  
  59. // * selects a entry in the tree
  60. //   param XULElement aItem
  61. function selectTreeItem(aItem)
  62. {
  63.   /* first make sure item's containers are open */
  64.   if (!aItem) return;
  65.   var tmp = aItem.parentNode;
  66.   while (tmp && tmp.nodeName != "tree") {
  67.     if (tmp.nodeName == "treeitem")
  68.       tmp.setAttribute("open", "true");
  69.     tmp = tmp.parentNode;
  70.   }
  71.  
  72.   /* then select the item */
  73.   var itemIndex = gDialog.sheetsTree.contentView.getIndexOfItem(aItem);
  74.   gDialog.sheetsTree.treeBoxObject.selection.select(itemIndex);
  75.   /* and make sure it is visible in the clipping area of the tree */
  76.   gDialog.sheetsTree.treeBoxObject.ensureRowIsVisible(itemIndex);
  77. }
  78.  
  79. // * gets a rule's index in its DOMCSSRuleList container
  80. //   param DOMCSSRuleList rulelist
  81. //   param DOMCSSRule rule
  82. //   return integer
  83. function getRuleIndexInRulesList(rulelist, rule)
  84. {
  85.   if (!rule || !rulelist)
  86.     return -1;
  87.  
  88.   var i;
  89.   for (i=0; i<rulelist.length; i++) {
  90.     if (rulelist.item(i) == rule) {
  91.       return i;
  92.     }
  93.   }
  94.   return -1;
  95. }
  96.  
  97. // * opens a file picker and returns a file: URL. If openOnly is true,
  98. //   the filepicker's mode is "open"; it is "save" instead and that allows
  99. //   to pick new filenames
  100. //   param boolean openOnly
  101. function getLocalFileURL(openOnly)
  102. {
  103.   var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  104.   var fileType = "*";
  105.   if (openOnly)
  106.     fp.init(window, gDialog.bundle.getString("SelectCSSFile"), nsIFilePicker.modeOpen);
  107.   else
  108.     fp.init(window, gDialog.bundle.getString("SelectCSSFile"), nsIFilePicker.modeSave);
  109.   
  110.   // Default or last filter is "All Files"
  111.   fp.appendFilters(nsIFilePicker.filterAll);
  112.  
  113.   // set the file picker's current directory to last-opened location saved in prefs
  114.   SetFilePickerDirectory(fp, fileType);
  115.  
  116.   /* doesn't handle *.shtml files */
  117.   try {
  118.     var ret = fp.show();
  119.     if (ret == nsIFilePicker.returnCancel)
  120.       return null;
  121.   }
  122.   catch (ex) {
  123.     dump("filePicker.chooseInputFile threw an exception\n");
  124.     return null;
  125.   }
  126.   // SaveFilePickerDirectory(fp, fileType);
  127.   
  128.   return fp.file ? getURLSpecFromFile(fp.file) : null;
  129. }
  130.  
  131. // blatantly stolen from Venkman
  132. function getURLSpecFromFile (file)
  133. {
  134.     if (!file)
  135.         return null;
  136.  
  137.     const IOS_CTRID = "@mozilla.org/network/io-service;1";
  138.     const LOCALFILE_CTRID = "@mozilla.org/file/local;1";
  139.  
  140.     const nsIIOService = Components.interfaces.nsIIOService;
  141.     const nsILocalFile = Components.interfaces.nsILocalFile;
  142.     const nsIFileProtocolHandler = Components.interfaces.nsIFileProtocolHandler;
  143.     
  144.     if (typeof file == "string")
  145.     {
  146.         var fileObj =
  147.             Components.classes[LOCALFILE_CTRID].createInstance(nsILocalFile);
  148.         fileObj.initWithPath(file);
  149.         file = fileObj;
  150.     }
  151.     
  152.     var service = Components.classes[IOS_CTRID].getService(nsIIOService);
  153.     var fileHandler = service.getProtocolHandler("file")
  154.                              .QueryInterface(nsIFileProtocolHandler);
  155.     return fileHandler.getURLSpecFromFile(file);
  156. }
  157.  
  158. // * Debug only...
  159. function doDump(text, value) {
  160.   dump("===> " + text + " : " + value + "\n");
  161. }
  162.  
  163. function ClearTreeSelection(tree) {
  164.   if (tree)
  165.     tree.treeBoxObject.selection.clearSelection();
  166. }
  167.